1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use super::*;
mod constraint;
mod dependency;
mod instant;
mod linear;
mod matches;
mod relationship;
pub use constraint::*;
pub use dependency::*;
pub use instant::*;
pub use linear::*;
pub use matches::*;
pub use relationship::*;
#[derive(Clone, Eq, PartialEq)]
pub struct Lifetime {
constraint: Constraint,
fv: SymbolSet,
code: u64,
}
impl Lifetime {
pub fn new(constraint: Constraint) -> Lifetime {
let fv = constraint.fv();
let mut tmp = Lifetime {
constraint,
fv,
code: 0,
};
tmp.fix_code();
tmp
}
pub fn free() -> Lifetime {
Self::new(Constraint::default())
}
pub fn get_hasher() -> AHasher {
AHasher::new_with_keys(34, 2123)
}
fn fix_code(&mut self) {
let mut hasher = Self::get_hasher();
self.constraint.hash(&mut hasher);
self.code = hasher.finish()
}
}
impl Debug for Lifetime {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
write!(fmt, "Lifetime{:#?}", self.constraint)
}
}
#[allow(clippy::derive_hash_xor_eq)]
impl Hash for Lifetime {
#[inline]
fn hash<H: Hasher>(&self, hasher: &mut H) {
self.code().hash(hasher)
}
}
impl Value for Lifetime {
#[inline]
fn is_ty(&self) -> bool {
true
}
#[inline]
fn is_groupoid(&self) -> bool {
false
}
#[inline]
fn ty(&self) -> &ValId {
&*SET
}
#[inline]
fn fv(&self) -> &SymbolSet {
&self.fv
}
#[inline]
fn is_lifetime(&self) -> bool {
true
}
#[inline]
fn into_enum(self) -> ValueEnum {
ValueEnum::Lifetime(self)
}
#[inline]
fn into_valid(self) -> ValId {
ValId::new_direct(ValueEnum::Lifetime(self))
}
#[inline]
fn code(&self) -> u64 {
self.code
}
fn contains(&self, value: &ValId) -> Result<Match, Error> {
let _constraint = value.instant_constraint()?;
unimplemented!()
}
}
lazy_static! {
pub static ref FREE_LIFETIME: ValId = ValId::new_direct(ValueEnum::Lifetime(Lifetime::free()));
}